<template>
  <transition name="my-confirm">
    <div
      class="confirm"
      v-if="isShow"
      @click="!option.forbriden && handleClose()"
    >
      <div class="con_box" @click.stop="() => {}">
        <h3>{{ option.title }}</h3>
        <p class="con_message">{{ option.message }}</p>
        <div class="btn">
          <span @click.stop="handleClose()" v-if="option.button.cancelText">{{
            option.button.cancelText
          }}</span>
          <span @click.stop="handleOk()" v-if="option.button.okText">{{
            option.button.okText
          }}</span>
        </div>
      </div>
    </div>
  </transition>
</template>
<script>
export default {
  data() {
    return {
      isShow: false,
      option: {
        title: "提示",
        message: "确定进行此操作？",
        button: {
          okText: "确定",
          // cancelText: "取消",
        },
        forbriden: false,
      },
    };
  },
  methods: {
    handleClose() {
      console.log("关闭");
    },
    handleOk() {
      console.log("确定");
    },
  },
};
</script>
<style lang="scss" scoped>
.confirm {
  background-color: rgba(0, 0, 0, 0.7);
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  .con_box {
    width: 270px;
    background: #ffffff;
    border-radius: 10px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1;
    text-align: center;
    color: #4d5c82;
    padding: 15px;
    box-sizing: border-box;
    > h3 {
      font-size: 20px;
      margin-top: 10px;
      margin-bottom: 20px;
    }
    > p {
      font-size: 17px;
      margin-bottom: 30px;
      overflow: scroll;
      max-height: 200px;
    }
    .btn {
      display: flex;
      justify-content: space-between;
      > span {
        display: block;
        // width: 114px;
        flex: 1;
        background-color: #e0e5f5;
        text-align: center;
        line-height: 44px;
        font-size: 17px;
      }
      > span:last-of-type {
        background-color: #1288fe;
        color: #ffffff;
      }
    }
  }
}
// 命名动画
.my-confirm-enter,
.my-confirm-leave-to {
  opacity: 0;
}
.my-confirm-enter-active,
.my-confirm-leave-active {
  transition: all 0.3s;
}
</style>
